package lium.lbs.lbsim.activity

import android.os.Bundle
import android.text.TextUtils
import android.view.View
import com.lmlibrary.Constants
import com.lmlibrary.bean.ResponseBean
import com.lzy.okgo.model.Response
import kotlinx.android.synthetic.main.activity_compliant.*
import lium.lbs.lbsim.R
import lium.lbs.lbsim.bean.GroupInfoBean
import lium.lbs.lbsim.utils.SpUtils
import lium.lbs.lbsim.utils.ToastUtils
import lium.lbs.lbsim.utils.callbck.DialogCallback
import java.util.HashMap

class CompliantActivity : BaseActivity() {

    var groupId: String? = null

    override fun getLayoutId(): Int {
        return R.layout.activity_compliant
    }


    override fun initView(savedInstanceState: Bundle?) {
        setTitleWithBack("投诉")
        addOnClickListeners(
            R.id.to_complain
        )
        groupId = intent.getStringExtra("groupID")
    }


    override fun onClick(v: View?) {
        super.onClick(v)
        when (v!!.id) {
            R.id.to_complain -> {
                getDataCompliant()
            }

        }

    }


    fun getDataCompliant() {
        if (TextUtils.isEmpty(complain_content.text.toString())){
            return
        }
        val param = HashMap<String, String>()
        param["memberId"] = SpUtils.getInstance().get(Constants.memberId, "") as String
        param["groupId"] = groupId.toString()
        param["content"] = complain_content.text.toString()
        postData(
            "/group/makeCompliant",
            param,
            object : DialogCallback<ResponseBean<GroupInfoBean>>(this) {
                override fun onSuccess(response: Response<ResponseBean<GroupInfoBean>>) {
                    setDataList(response.body().msg)
                }
            })
    }

    fun setDataList(msg: String) {
        ToastUtils.showLongToast(msg)
        setResult(200)
        finish()
    }

    override fun getNetWorkData() {

    }
}
